<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="挂号单号" prop="registrationId">
        <el-input
          v-model="queryParams.registrationId"
          placeholder="请输入挂号单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="患者姓名" prop="patientName">
        <el-input
          v-model="queryParams.patientName"
          placeholder="请输入患者姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="chargeList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="订单号" align="center" prop="orderID" />
      <el-table-column label="挂号单号" align="center" prop="registrationId" />
      <el-table-column label="收费单号" align="center" prop="chargeId" />
      <el-table-column label="患者姓名" align="center" prop="patientName" />
      <el-table-column label="退费总金额" align="center" prop="refundAmount" />
      <el-table-column label="订单状态" align="center" prop="orderStatus" :formatter="statusFormat" />
      <el-table-column label="创建时间" align="center" prop="supBuildTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.supBuildTime ,'{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleView(scope.row)"
            v-hasPermi="['chargesystem:chargequery:detailquery']"
          >详细信息</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />



    <!-- 任务日志详细 -->
    <el-dialog title="收费详细" :visible.sync="open" width="700px" append-to-body>
      <el-table v-loading="loading" :data="chargeDetalList" @selection-change="handleSelectionChange">

        <el-table-column label="订单ID" align="center" prop="orderId"/>
        <el-table-column label="药品ID" align="center" prop="drugId"/>
        <el-table-column label="药品名称" align="center" prop="drugName"/>
        <el-table-column label="药品价格" align="center" prop="drugPrice"/>
        <el-table-column label="药品数量" align="center" prop="drugAmount"/>
        <el-table-column label="状态" align="center" prop="status" :formatter="statusFormat2"/>
        <!--   <template slot-scope="scope">
             <span>{{ parseTime(scope.row.regSdate ,'{y}-{m}-{d}') }}</span>
           </template>-->
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="open = false">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
//import { listPost, getPost, delPost, addPost, updatePost, exportPost } from "@/api/chargequery/pcharge";
import {listSup,getCharge} from "@/api/returnMoney/pcharge";

export default {
  name: "chargequery",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      openView : false,
      // 总条数
      total: 0,
      // 岗位表格数据
      chargeList: [],
      chargeDetalList:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 状态数据字典
      statusOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        registrationId: undefined,
        patientName: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        postName: [
          { required: true, message: "岗位名称不能为空", trigger: "blur" }
        ],
        postCode: [
          { required: true, message: "岗位编码不能为空", trigger: "blur" }
        ],
        postSort: [
          { required: true, message: "岗位顺序不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("sys_return_status").then(response => {
      this.statusOptions = response.data;
    });
  },
  methods: {
    /** 查询岗位列表 */
    getList() {
      this.loading = true;
      listSup(this.queryParams).then(response => {
        this.chargeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 岗位状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.orderStatus);
    },
    statusFormat2(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },

    /** 任务详细信息 */
    handleView(row) {
      getCharge(row.orderID).then(response => {
        this.chargeDetalList = response.rows;
        this.total = response.total;
        this.open = true;

      });
    },
    // 表单重置
    reset() {
      this.form = {
        postId: undefined,
        postCode: undefined,
        postName: undefined,
        postSort: 0,
        status: "0",
        remark: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },



  }
};
</script>
